application.onAppStart = function()
{	
	// Get the server shared object 'users_so'
	application.users_so = SharedObject.get("ChatUsers");
	application.dashboard_so = SharedObject.get("Dashboard");
	application.bckgndColor_so = SharedObject.get("BckgndColor");
	
	application.bckgndColor_so.setProperty("color", 0xFFFFFF);
	
	// Initialize the unique user ID
	application.nextId = 0;
}

application.onConnect = function(newClient, userName)
{
	// Make this new client's name the user's name
	newClient.name = userName;
	
	// Create a unique ID for this user while incrementing the application.nextID.
	newClient.id = "u" + application.nextId++;
	
	// Update the 'users_so' shared object with the user's name
	application.users_so.setProperty(newClient.name, userName);
	
	// Accept the client's connection
 	application.acceptConnection(newClient);

	// The client will call this function to get the server
	// to accept the message, add the user's name to it, and
	// send it back out to all connected clients.
	newClient.msgFromClient = function(msg) {	
		msg = userName + ": " + msg + "\n";
		application.users_so.send("msgFromSrvr", msg);
	}
}

application.onDisconnect = function(client)
{
	trace("disconnect: " + client.name);
	application.users_so.setProperty(client.name, null);
}